/*
package com.module.oa.controller;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestActiviti {

    public static void main(String[] args) {
        testCreateDbTable();
    }
    */
/**
     * 生成 activiti的数据库表
     *//*

    @Test
    public static void testCreateDbTable() {
        //使用classpath下的activiti.cfg.xml中的配置创建processEngine
        //如果使用默认则需要上面activiti.cfg.xml配置
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        System.out.println(processEngine);
    }

    //部署
    @Test
    public void test01() {
        //1、创建ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2、得到RepositoryService实例
        RepositoryService repositoryService = processEngine.getRepositoryService();
        //3、使用RepositoryService进行部署
        Deployment deploy = repositoryService.createDeployment().addClasspathResource("activiti/attendance_leave.bpmn20.xml")
                .addClasspathResource("activiti/leave.png")
                .name("请假审批流程")
                .deploy();
        //4、输出部署信息
        System.out.println("部署id："+deploy.getId());
        System.out.println("部署的任务名称："+deploy.getName());
    }

    //启动流程
    @Test
    public void testDeploy() {
        //1.创建ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //创建TaskService
        TaskService taskService = processEngine.getTaskService();

        Map<String, Object> variables = new HashMap<>();
        //张三就是在bpmn中Assignee配置的参数
        variables.put("何正贤", "请假申请");
        //3.创建流程实例  流程定义的key需要知道 holiday
        ProcessInstance processInstance = ProcessEngines.getDefaultProcessEngine()
                .getRuntimeService()
                .startProcessInstanceByKey("attendance_leave", variables);
        Task tmp = taskService.createTaskQuery()
                .processInstanceId(processInstance.getProcessInstanceId()).singleResult();
        tmp.setAssignee("lxd");
        //完成此节点。由下一节点审批。完成后act_ru_task会创建一条由下节点审批的数据
        taskService.complete(tmp.getId(),variables);
        //4.输出实例的相关信息
        System.out.println( "流程部署ID：" + processInstance.getDeploymentId() );
        System.out.println( "流程定义ID：" + processInstance.getProcessDefinitionId());
        System.out.println( "流程实例ID：" + processInstance.getId() );
        System.out.println( "活动ID：" + processInstance.getActivityId() );
    }


    @Test
    //查询任务
    public void test(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //创建TaskService
        TaskService taskService = processEngine.getTaskService();
        //根据流程key 和 任务负责人 查询任务
        List<Task> list = taskService.createTaskQuery()
                .processDefinitionKey("attendance_leave") //流程Key
                .taskAssignee("lxd")//只查询该任务负责人的任务
                .list();
        System.err.println("待审批任务数量-----------："+list.size());
        for (Task task : list) {
            System.out.println("流程实例id：" + task.getProcessInstanceId());
            System.out.println("任务id：" + task.getId());
            System.out.println("任务负责人：" + task.getAssignee());
            System.out.println("任务名称：" + task.getName());
        }

    }

    //审批流程
    @Test
    public void test1(){
        //1.创建ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //创建TaskService
        TaskService taskService = processEngine.getTaskService();
        //根据角色信息获取自己的待办
        List<Task> T = taskService.createTaskQuery().taskAssignee("lxd").list();
        if(!ObjectUtils.isEmpty(T)) {
            for (Task item : T) {
                Map<String, Object> variables = new HashMap<>();
                variables.put("lxd", "lxd");
                variables.put("isSuccess", true);
                item.setAssignee("ccy");
                //增加审批备注
                taskService.addComment(item.getId(),item.getProcessInstanceId(),"组长同意");
                //完成此次审批。由下节点审批
                taskService.complete(item.getId(), variables);
            }
        }
    }

    // 结束流程
    @Test
    public void test02() {
        //1.创建ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //        创建TaskService
        TaskService taskService = processEngine.getTaskService();
        //act_re_execution id
        String taskId = "25015";
        //        任务负责人
        String assingee = "ccy";
        Task task = taskService.createTaskQuery()
                .taskId(taskId)
                .taskAssignee(assingee)
                .singleResult();
        if (task != null) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("agree", 1);
            taskService.complete(taskId, map);

            System.out.println("完成任务");
        }

    }
}
*/
